package com.cf.r1049;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class a {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int T = Integer.parseInt(br.readLine());
        while (T-- > 0) {
            solve();
        }
        out.flush();
        out.close();
        br.close();
    }

    static void solve() throws IOException {
        String[] in = br.readLine().split(" ");
        long n = Long.parseLong(in[0]);
        in = br.readLine().split(" ");
        char[] s = in[0].toCharArray();
        int cnt0 = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] == '0') {
                cnt0++;
            }
        }
        int x = cnt0;
        for (int i = 0; i < x; i++) {
            if (s[i] == '0') {
                cnt0--;
            }
        }
        out.println(cnt0);
    }
}
